#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int c = nums.size() - 1;
        int count = 0;
        while (c > 1)
        {
            int b = c - 1;
            int a = 0;
            while (a < b)
            {
                if (nums[a] + nums[b] > nums[c])
                {
                    count += b - a;
                    b--;
                }
                else
                {
                    a++;
                }
            }
            c--;
        }
        return count;
    }
};